package org.gy.T2.c;

import java.util.Random;

public class MyUtils {
    public static String createCode(int n){
        //1.定义⼀个字符串，⽤来记录产⽣的验证码
        String code = "";
        //2.验证码是由所有的⼤写字⺟、⼩写字⺟或者数字字符组成
        //这⾥先把所有的字符写成⼀个字符串，⼀会从字符串中随机找字符
        String data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKMNOPQRSTUVWXYZ";
        //3.循环n次，产⽣n个索引,再通过索引获取字符
        Random r = new Random();
        for (int i = 0; i < n; i++) {
            int index = r.nextInt(data.length());
            char ch = data.charAt(index);
            code += ch;
        }
        return code;
    }
}
